﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKRevitKernel.FormUtility;
using YJKCopyModel.GeothermalPipeQuickModel;

namespace YJKCopyModel.Forms.GeothermalPipe
{
	public partial class GeothermalPipeDifSetForm : System.Windows.Forms.Form
	{
		public CloseGeothermalDlgType DlgCloseType
		{
			get
			{
				return this.m_DlgCloseType;
			}
		}

		public GeothermalPipeDifSetForm(UIDocument inputUIDoc)
		{
			this.InitializeComponent();
			this.m_uiDoc = inputUIDoc;
		}

		private void GeothermalPipeDifSetForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.txtboxSupplyColor.Text = "█RGB 000 255 255";
			this.txtboxBackColor.Text = "█RGB 000 255 255";
			Dictionary<string, Element> allLineType = GetRevitProjectData.GetAllLineType(this.m_uiDoc.Document);
			this.radDifSameLevelChange.Checked = true;
			GeothermalFormData.LineType = allLineType;
			this.comboxSupplyLineType.Items.Add("实线");
			this.comboxSupplyLineType.Items.AddRange(allLineType.Keys.ToArray<string>());
			bool flag = allLineType.Count > 0;
			if (flag)
			{
				this.comboxSupplyLineType.SelectedItem = "实线";
			}
			this.comboxSupplyWidth.Items.AddRange(GetRevitProjectData.LineWidth().ToArray());
			this.comboxSupplyWidth.SelectedIndex = 13;
			GeothermalFormData.LineType = allLineType;
			this.comboxBackLineType.Items.Add("实线");
			this.comboxBackLineType.Items.AddRange(allLineType.Keys.ToArray<string>());
			bool flag2 = allLineType.ContainsKey("长划线");
			if (flag2)
			{
				this.comboxBackLineType.SelectedItem = "长划线";
			}
			this.comboxBackWidth.Items.AddRange(GetRevitProjectData.LineWidth().ToArray());
			this.comboxBackWidth.SelectedIndex = 13;
			this.AddControlGroup();
			this.m_ControlInfoManager = new ControlInfoManager(this, this.m_lstControlGroup, null, null);
			this.m_ControlInfoManager.SetControlInfoToForm();
			System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtboxSupplyColor.Text);
			this.txtboxSupplyColor.ForeColor = xmlDataColor;
			System.Drawing.Color xmlDataColor2 = ColorSet.GetXmlDataColor(this.txtboxBackColor.Text);
			this.txtboxBackColor.ForeColor = xmlDataColor2;
			bool flag3 = !allLineType.Keys.ToArray<string>().Contains(this.comboxSupplyLineType.Text);
			if (flag3)
			{
				this.comboxSupplyLineType.Items.Clear();
				this.comboxSupplyLineType.Items.Add("实线");
				this.comboxSupplyLineType.Items.AddRange(allLineType.Keys.ToArray<string>());
				this.comboxSupplyLineType.SelectedItem = "实线";
			}
			bool flag4 = !allLineType.Keys.ToArray<string>().Contains(this.comboxBackLineType.Text);
			if (flag4)
			{
				this.comboxBackLineType.Items.Clear();
				this.comboxBackLineType.Items.Add("实线");
				this.comboxBackLineType.Items.AddRange(allLineType.Keys.ToArray<string>());
				this.comboxBackLineType.SelectedItem = "实线";
			}
		}

		private void AddControlGroup()
		{
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comboxSupplyLineType, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.txtboxSupplyColor, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comboxSupplyWidth, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comboxBackLineType, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.txtboxBackColor, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comboxBackWidth, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radDifAreaChange, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radDifSameLevelChange, false));
		}

		private void GeothermalPipeDifSetForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyValue == 27;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private void txtboxSupplyColor_Click(object sender, EventArgs e)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtboxSupplyColor.Text);
			bool flag = !xmlDataColor.IsKnownColor;
			if (flag)
			{
				int[] array = new int[16];
				array[0] = ColorSet.GetIntAboutColor(xmlDataColor);
				colorDialog.CustomColors = array;
			}
			colorDialog.Color = xmlDataColor;
			DialogResult dialogResult = colorDialog.ShowDialog();
			bool flag2 = DialogResult.OK == dialogResult;
			if (flag2)
			{
				string newRGB = ColorSet.getNewRGB(colorDialog.Color.R);
				string newRGB2 = ColorSet.getNewRGB(colorDialog.Color.G);
				string newRGB3 = ColorSet.getNewRGB(colorDialog.Color.B);
				string text = string.Concat(new string[]
				{
					"█RGB ",
					newRGB,
					" ",
					newRGB2,
					" ",
					newRGB3
				});
				this.txtboxSupplyColor.ForeColor = colorDialog.Color;
				this.txtboxSupplyColor.Text = text;
			}
		}

		private void txtboxBackColor_Click(object sender, EventArgs e)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtboxBackColor.Text);
			bool flag = !xmlDataColor.IsKnownColor;
			if (flag)
			{
				int[] array = new int[16];
				array[0] = ColorSet.GetIntAboutColor(xmlDataColor);
				colorDialog.CustomColors = array;
			}
			colorDialog.Color = xmlDataColor;
			DialogResult dialogResult = colorDialog.ShowDialog();
			bool flag2 = DialogResult.OK == dialogResult;
			if (flag2)
			{
				string newRGB = ColorSet.getNewRGB(colorDialog.Color.R);
				string newRGB2 = ColorSet.getNewRGB(colorDialog.Color.G);
				string newRGB3 = ColorSet.getNewRGB(colorDialog.Color.B);
				string text = string.Concat(new string[]
				{
					"█RGB ",
					newRGB,
					" ",
					newRGB2,
					" ",
					newRGB3
				});
				this.txtboxBackColor.ForeColor = colorDialog.Color;
				this.txtboxBackColor.Text = text;
			}
		}

		private void btnDifOK_Click(object sender, EventArgs e)
		{
			GeothermalFormData.LineTypeSupply = this.comboxSupplyLineType.Text;
			GeothermalFormData.LineWidthSupply = this.comboxSupplyWidth.Text;
			GeothermalFormData.LineColorSupply = this.txtboxSupplyColor.Text;
			GeothermalFormData.LineTypeBack = this.comboxBackLineType.Text;
			GeothermalFormData.LineWidthBack = this.comboxBackWidth.Text;
			GeothermalFormData.LineColorBack = this.txtboxBackColor.Text;
			bool @checked = this.radDifAreaChange.Checked;
			if (@checked)
			{
				GeothermalFormData.IsArea = true;
				GeothermalFormData.IsLevel = false;
				this.m_DlgCloseType = CloseGeothermalDlgType.ByArea;
			}
			else
			{
				GeothermalFormData.IsArea = false;
				GeothermalFormData.IsLevel = true;
				this.m_DlgCloseType = CloseGeothermalDlgType.ByLevel;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void radDifSameLevelChange_Click(object sender, EventArgs e)
		{
			bool @checked = this.radDifSameLevelChange.Checked;
			if (@checked)
			{
				this.radDifAreaChange.Checked = false;
			}
			else
			{
				this.radDifAreaChange.Checked = true;
			}
		}

		private void radDifAreaChange_Click(object sender, EventArgs e)
		{
			bool @checked = this.radDifAreaChange.Checked;
			if (@checked)
			{
				this.radDifSameLevelChange.Checked = false;
			}
			else
			{
				this.radDifSameLevelChange.Checked = true;
			}
		}

		private void GeothermalPipeDifSetForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			bool flag = this.m_ControlInfoManager != null;
			if (flag)
			{
				this.m_ControlInfoManager.GetControlInfoToXml();
			}
		}

		private void txtboxSupplyColor_KeyPress(object sender, KeyPressEventArgs e)
		{
			e.Handled = true;
		}

		private void txtboxBackColor_KeyPress(object sender, KeyPressEventArgs e)
		{
			e.Handled = true;
		}

		private void txtboxSupplyColor_TextChanged(object sender, EventArgs e)
		{
			bool flag = string.IsNullOrWhiteSpace(this.txtboxSupplyColor.Text);
			if (flag)
			{
				this.txtboxSupplyColor.Text = this.defaultText;
				System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtboxSupplyColor.Text);
				this.txtboxSupplyColor.ForeColor = xmlDataColor;
			}
		}

		private void txtboxBackColor_TextChanged(object sender, EventArgs e)
		{
			bool flag = string.IsNullOrWhiteSpace(this.txtboxBackColor.Text);
			if (flag)
			{
				this.txtboxBackColor.Text = this.defaultText;
				System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtboxBackColor.Text);
				this.txtboxBackColor.ForeColor = xmlDataColor;
			}
		}

		private ControlInfoManager m_ControlInfoManager = null;

		private List<KeyValuePair<System.Windows.Forms.Control, bool>> m_lstControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();

		private UIDocument m_uiDoc = null;

		private CloseGeothermalDlgType m_DlgCloseType;

		private string defaultText = "█RGB 000 255 255";
	}
}
